wip: add test for missing instance_id in SpannerMetricsTracerFactory#1482
wip: add test for missing instance_id in SpannerMetricsTracerFactory#1482shutootaki wants to merge 5 commits intogoogleapis:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello @shutootaki, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on addressing a potential bug related to the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds a test to reproduce a bug where instance_id is missing in SpannerMetricsTracerFactory. This is a good approach. My review includes a couple of suggestions:
- There is some temporary debug logging in
metrics_exporter.pythat should be removed. - The new test script
test_instance_id_bug.pyshould be converted into a properpytesttest case and moved to thetests/unitdirectory to be part of the automated test suite.
Please see the detailed comments for suggestions on how to address these points.
test_instance_id_bug.py
Outdated
There was a problem hiding this comment.
This is a good start for a test case to reproduce the bug. To make it a standard test that can be run with the existing test suite, it should be converted to a pytest test.
Here are some suggestions:
- File Location: This file should be moved to the
tests/unit/directory so it can be discovered bypytest. - Use Assertions: Tests should use
assertstatements to check for expected outcomes instead of printing to the console. This allows the test runner to automatically determine if the test passes or fails. - Language Consistency: The comments and strings should be in English to maintain consistency with the rest of the codebase.
Here's a suggested revision of this test file:
"""
Test to reproduce the bug of missing instance_id in SpannerMetricsTracerFactory.
This test confirms that after SpannerMetricsTracerFactory is initialized,
instance_id is not included in client_attributes.
"""
import pytest
from google.cloud.spanner_v1.metrics.spanner_metrics_tracer_factory import (
SpannerMetricsTracerFactory,
)
from google.cloud.spanner_v1.metrics.constants import MONITORED_RES_LABEL_KEY_INSTANCE
pytest.importorskip("opentelemetry")
def test_instance_id_is_missing_in_factory_attributes():
"""Test to confirm that instance_id is not set in client_attributes."""
# Reset the singleton for testing purposes
SpannerMetricsTracerFactory._metrics_tracer_factory = None
# Initialize the factory
factory = SpannerMetricsTracerFactory(enabled=True)
# Check that instance_id is missing from the factory's attributes.
# This assertion is expected to pass with the bug present, and will
# fail once the bug is fixed, indicating the test needs to be updated.
assert MONITORED_RES_LABEL_KEY_INSTANCE not in factory.client_attributes
# Also check the tracer created by the factory
tracer = factory.create_metrics_tracer()
if tracer:
assert MONITORED_RES_LABEL_KEY_INSTANCE not in tracer.client_attributes
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Fixes #<issue_number_goes_here> 🦕